/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#ifndef CONNECT_WIZ_H
#define CONNECT_WIZ_H

#include <QtWidgets/QWizard>

#include "GenBank.h"
#include "SqlServer.h"

class ConnectFrame;
class QCheckBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QRadioButton;

class SnapshotWiz : public QWizard {
	Q_OBJECT
public:
	enum Page { PageIntro = 0, PageCreate, PageConnect, PageEmbedded, PagePostgre, 
					PageMySQL, PageUsers, PageGenBank, PageFinish };

	SnapshotWiz( QWidget *parent );
	virtual ~SnapshotWiz();

	bool	isDivisionSelected( Bio::GenBank::Division div ) const;
};

class GenBankWiz : public SnapshotWiz {
	Q_OBJECT
public:
	GenBankWiz( QWidget *parent, Bio::GenBank *genBank );
	virtual ~GenBankWiz();
};

class ConnectWiz : public SnapshotWiz {
	Q_OBJECT
public:
	ConnectWiz( QWidget *parent, Bio::GenBank *genBank, const QString &defConfigFile );
	virtual ~ConnectWiz();

	Bio::SqlServerSettings	getServerSettings() const;

	bool	isCreate() const;
};

class IntroPage : public QWizardPage {
	Q_OBJECT
public:
	IntroPage();
	~IntroPage();

	virtual int	nextId() const;

private:

	QRadioButton	*m_connectBtn, *m_createBtn;
};

class ConnectPage : public QWizardPage {
	Q_OBJECT
public:
	ConnectPage( const QString &defConfigFile );
	~ConnectPage();

	virtual int		nextId() const;
	virtual bool	isComplete() const;
	virtual void	initializePage();

private slots:

	void	updateComplete();

private:

	bool			m_complete;
	ConnectFrame	*m_frame;
};

class EmbeddedPage : public QWizardPage {
	Q_OBJECT
public:
	EmbeddedPage( const QString &defConfigFile );
	~EmbeddedPage();

	virtual int		nextId() const;
	virtual bool	isComplete() const;
	virtual void	initializePage();

private slots:

	void	updateComplete();
	void	browseLocation();

private:

	bool		m_complete;
	QLineEdit	*m_configPath;
};

class CreatePage : public QWizardPage {
	Q_OBJECT
public:
	CreatePage();
	~CreatePage();

	virtual int		nextId() const;
	virtual void	initializePage();

private:

	QRadioButton	*m_connectBtn, *m_embedBtn, *m_mysqlBtn, *m_postgreBtn;
};

class PostgrePage : public QWizardPage {
	Q_OBJECT
public:
	PostgrePage();
	~PostgrePage();

	virtual bool	validatePage();
	virtual int		nextId() const;
};

class MySQLPage : public QWizardPage {
	Q_OBJECT
public:
	MySQLPage();
	~MySQLPage();

	virtual bool	validatePage();
	virtual int		nextId() const;
};

class UsersPage : public QWizardPage {
	Q_OBJECT
public:
	UsersPage();
	~UsersPage();

	virtual int		nextId() const;
	virtual bool	isComplete() const;
	virtual void	initializePage();

private slots:

	void	updateComplete();

private:

	void	buildUI();
	void	setOnlineHelp();

	bool		m_complete;
	QGroupBox	*m_bioUserBox, *m_readOnlyBox;
	QLineEdit	*m_bioUserName, *m_bioPass1, *m_bioPass2, *m_readOnlyName, *m_readOnlyPass1, *m_readOnlyPass2;
};

class GenBankPage : public QWizardPage {
	Q_OBJECT
public:
	GenBankPage( Bio::GenBank *genBank );
	~GenBankPage();

	virtual int		nextId() const;
	virtual void	initializePage();

private slots:

	void	updateTotal();

private:

	void		initLayout();
	QCheckBox*	createDivisionCheckBox( int which );
	QString		sizeToText( double size );

	QCheckBox		*m_divBox[Bio::GenBank::NumDivisions];
	QLabel			*m_totalSizeLbl;
	Bio::GenBank	*m_genBank;
};

class FinishedPage : public QWizardPage {
	Q_OBJECT
public:
	FinishedPage( bool checkConnection );
	~FinishedPage();

	virtual int		nextId() const;
	virtual void	initializePage();

private:

	bool	m_checkConnection;
	QLabel	*m_lbl;
};

#endif // CONNECT_WIZ_H